import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../controller.dart';

/// 闪屏页Logo组件
/// 
/// 特性：
/// - 响应式缩放动画
/// - 美观的阴影效果
/// - 支持图片或图标显示
/// - 可自定义尺寸和样式
class SplashLogo extends GetView<SplashController> {
  /// Logo容器大小
  final double size;
  
  /// Logo图片路径（优先显示图片）
  final String? imagePath;
  
  /// Logo图标（图片不存在时使用）
  final IconData icon;
  
  /// Logo图标大小
  final double? iconSize;
  
  /// Logo背景色
  final Color? backgroundColor;
  
  /// Logo图标颜色
  final Color? iconColor;
  
  /// 是否显示阴影
  final bool showShadow;
  
  /// 图片适配方式
  final BoxFit imageFit;

  const SplashLogo({
    super.key,
    this.size = 120,
    this.imagePath,
    this.icon = Icons.flutter_dash,
    this.iconSize,
    this.backgroundColor,
    this.iconColor,
    this.showShadow = true,
    this.imageFit = BoxFit.contain,
  });

  @override
  Widget build(BuildContext context) {
    return Obx(() => AnimatedScale(
      scale: controller.logoScale.value,
      duration: const Duration(milliseconds: 100),
      child: Container(
        width: size,
        height: size,
        decoration: BoxDecoration(
          color: backgroundColor ?? Colors.white,
          borderRadius: BorderRadius.circular(size * 0.2),
          boxShadow: showShadow ? [
            BoxShadow(
              color: Colors.black.withValues(alpha: 0.3),
              blurRadius: size * 0.125,
              offset: Offset(0, size * 0.067),
              spreadRadius: 2,
            ),
          ] : null,
        ),
        child: _buildLogoContent(),
      ),
    ));
  }
  
  /// 构建Logo内容 - 优先显示图片，回退到图标
  Widget _buildLogoContent() {
    if (imagePath != null) {
      // 显示图片
      return ClipRRect(
        borderRadius: BorderRadius.circular(size * 0.2),
        child: Image.asset(
          imagePath!,
          width: size,
          height: size,
          fit: imageFit,
          errorBuilder: (context, error, stackTrace) {
            // 图片加载失败时回退到图标显示
            return _buildIconContent();
          },
        ),
      );
    } else {
      // 显示图标
      return _buildIconContent();
    }
  }
  
  /// 构建图标内容
  Widget _buildIconContent() {
    return Icon(
      icon,
      size: iconSize ?? size * 0.58,
      color: iconColor ?? Colors.deepPurple,
    );
  }
}
